<?php
header('Content-type:text/json;char-set:utf-8;');
require_once("../lib/common.php");
$route=filter("func");
switch($route){
	case "add_art":
		add_art();
		break;
	case "load":
		load();
		break;
	default:
		break;
}

function load(){
	$key=filter("key");
	//var_dump($key);exit;
	if(strlen($key)!=10){
		return false;
	}
	$data=F($key);
	$data=(array)$data;
	$data=$data['data'];
	//var_dump($data);exit;
	if($data){
		echo json_encode($data);
		exit;
	}
	
}
function prohtml($key){
	$tpl=T();
	$data=F($key);
	$data=(array)$data;
	$tpl->assign("data",$data['data']['content']); 
	$name=date("Y-m-d-H-i-s",$key).".html";
	$tpl->MakeHtmlFile($name,"article.html");
}

function add_art(){
	$from=filter("edit"); 
	$key=filter("key") ? filter("key"): time();
	$listdata=F("list");
	//文章模型数据
	$art["title"]=$from["title"];
	$art["body"]=$from["body"]; 
	//列表模型数据
	$list["title"]=$from["title"];
	$list["key"]=$key; 

	$keydata=F($key);
	$keydata->saveo("content",$art);
	$listdata->saveo($key,$list);
	
	prohtml($key);
	echo json_encode(["status"=>"1"]);
}
?>